﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

using Hong.Business.Business_LeadingCockpit;
using Hong.Common.RabbitMQ;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

using MiniExcelLibs;

namespace WeHongshibApI.Controllers.Controllers_LeadingCockpit
{
    [ApiExplorerSettings(GroupName = "Leading")]
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class LeadingCockpitController : ControllerBase
    {
        #region 构造器注入
        private static LeadingCockpitBusiness cock;
        public LeadingCockpitController(LeadingCockpitBusiness _cock)
        {
            cock = _cock;;
        }
        #endregion

        #region 领导驾驶舱

        #region 合同与项目综合统计（显示、查询）
        [HttpGet]
        public IActionResult GetStatistics(string DName = "")
        {
            var list = cock.GetStatistics(DName);
            return Ok(list);
        }
        #endregion

        #region 合同与项目综合统计导出
        [HttpGet]
        public IActionResult GetExecel()
        {
            var list = cock.GetExecel();
            var memoryStream = new MemoryStream();
            memoryStream.SaveAs(list);
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "applicatio/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = "合同与项目综合统计.xlsx"
            };
        }
        #endregion

        #region 合同收款综合统计
        [HttpGet]
        public IActionResult GetContInfo(int pageindex, int pagesize, string ContractName="", string OriginalContractPrice="", string ContractNumber = "", string RealyContractPrice = "",string ClientId="")
        {
            var list = cock.GetContInfo(pageindex, pagesize, ContractName, OriginalContractPrice,ContractNumber,RealyContractPrice, ClientId);
            return Ok(list);
        }
        #endregion

        #region 合同收费
        [HttpGet]
        public IActionResult FindInfo(string ContractId)
        {
            var list = cock.FindInfo(ContractId);
            return Ok(list);
        }
        #endregion

        #region 合同收款综合统计导出
        [HttpGet]
        public IActionResult GetExecel1()
        {
            var list = cock.GetExecel1();
            var memoryStream = new MemoryStream();
            memoryStream.SaveAs(list);
            memoryStream.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(memoryStream, "applicatio/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = "合同收款综合统计.xlsx"
            };
        }
        #endregion

        #region 项目综合统计
        [HttpGet]
        public IActionResult GetProject(string DName, string Conid, int? Scaleid, int? Lxid, int? Jxid, int? Ztid, int? Wcid)
        {
            var list = cock.GetProject(DName, Conid, Scaleid, Lxid, Jxid, Ztid, Wcid);
            return Ok(list);
        }
        #endregion

        #region 获取部门信息
        [HttpGet]
        public IActionResult GetDept()
        {
            var list = cock.GetDept();
            return Ok(list);
        }
        #endregion

        #region 获取甲方联系人
        [HttpGet]
        public IActionResult ShowReponsble()
        {
            var list = cock.ShowReponsble();
            return Ok(list);
        }
        #endregion

        #region 合同综合统计
        [HttpGet]
        public IActionResult GetContract(string D = "", string Y = "", string O = "", string R = "", string W = "", string C = "")
        {
            var list = cock.GetContract(D,Y,O,R,W,C);
            return Ok(list);
        }
        #endregion

        #region 部门合同额同比(累计)
        [HttpGet]
        public IActionResult GetContract2s(string DName = "")
        {
            var list = cock.GetContract2s(DName);
            return Ok(list);
        }
        #endregion

        #region 合同额对比统计(月)
        [HttpGet]
        public IActionResult GetContract3s(string DName = "")
        {
            var list = cock.GetContract3s(DName);
            return Ok(list);
        }
        #endregion

        #region 合同收费详情
        [HttpGet]
        public IActionResult GetContract4s(string DName = "")
        {
            var list = cock.GetContract4s(DName);
            return Ok(list);
        }
        #endregion

        [HttpGet]
        public IActionResult GetProject2()
        {
            var list = cock.GetProject2();
            return Ok(list);
        }

        [HttpGet]
        public IActionResult GetProject4(string DName = "")
        {
            var list = cock.GetProject4(DName);
            return Ok(list);
        }

            #endregion
        }
}
